﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
*/

function SetAll(sender) {
    re1 = new RegExp('cbProduct');
    re2 = new RegExp('btnImportProducts');

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') {
            if (re1.test(elm.name))
                elm.checked = sender.checked;
        } else if (elm.type == 'submit') {
            if (re2.test(elm.name))
                elm.disabled = !sender.checked;
        }
    }
}

function Select() {
    re1 = new RegExp('cbProduct');
    re2 = new RegExp('cbSelectAll');
    re3 = new RegExp('btnImportProductsTop');
    re4 = new RegExp('btnImportProductsBottom');
    all = true;
    none = true;

    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm1 = document.forms[0].elements[i];
        if (elm1.type == 'checkbox') {
            if (re2.test(elm1.name)) {
                cbSetAll = elm1;
            }
            else {
                if (re1.test(elm1.name))
                    if (elm1.checked == false) {
                    all = false;
                } else if (elm1.checked == true) {
                    none = false;
                }
            }
        } else if (elm1.type == 'submit') {
            if (re3.test(elm1.name)) {
                btnImportTop = elm1;
            } else if (re4.test(elm1.name)) {
                btnImportBottom = elm1;
            }
        }
    }
    cbSetAll.checked = all;
    btnImportTop.disabled = none;
    btnImportBottom.disabled = none;
}
